<? 
	// TODO CREATE A PEAK LOGON TIME!!!!
	require_once('./misc.php');
		global $db, $yap, $jackknife;
	
	$NUM_PER_PAGE = 30;

	$p = (isset($_GET['p']))?$_GET['p']:null;
	$QUERY = (isset($_SERVER['QUERY_STRING']))?$_SERVER['QUERY_STRING']:'';
	$CUR_PAGE = $_SERVER['PHP_SELF']."?".$QUERY;

	$page = (isset($_REQUEST['page']))?$_REQUEST['page']:1;

	$query_list_members = mysql_query('SELECT * FROM corpMemberTracking', $yap);
	$total_members = mysql_num_rows($query_list_members);
	$total_pages = ceil(($total_members/$NUM_PER_PAGE));

?>
<table width='100%'>
	<tr><td colspan=4>
	<form action="<?=$CUR_PAGE;?>"> 
		<input name="p" type="hidden" value="<?=$p;?>"> SEARCH : 
		<input type="text" name="_name" onfocus="if(this.value=='name'){_name.value='';loc.value='';ship.value='';}" value="name" /> 
		<input type="text" name="loc" onfocus="if(this.value=='location'){_name.value='';loc.value='';ship.value='';}" value="location" /> 
		<input type="text" name="ship" onfocus="if(this.value=='ship'){_name.value='';loc.value='';ship.value='';}" value="ship" /> 

		<input id="search_btn" type="submit" value="Search" /> 
	</form>
	</td>
	<tr>
		<td><b>Name</b></td>
		<td><b>location</b></td>
		<td><b>Ship</b></td>
	</tr>
<?

	$sN = (isset($_REQUEST['_name']))?$_REQUEST['_name']:false;
	$sL = (isset($_REQUEST['loc']))?$_REQUEST['loc']:false;
	$sS = (isset($_REQUEST['ship']))?$_REQUEST['ship']:false;

	$sN = ($sN!="name")?mres($sN):false;
	$sL = ($sL!="location")?mres($sL):false;
	$sS = ($sS!="ship")?mres($sS):false;
	
	$searchby = false;
	$searchtext = "";

	if ($sN){
		$searchby = "name";
		$searchtext = $sN;
	}
	if ($sL){
		$searchby = "location";
		$searchtext = $sL;
	}
	if ($sS){
		$searchby = "shipType";
		$searchtext = $sS;
	}
	if ($searchby) {
	$where = "WHERE $searchby LIKE '%$searchtext%'";
	} else $where="";

	$query_all_members = mysql_query('SELECT * FROM corpMemberTracking '.$where.' ORDER BY name ASC LIMIT '.(($page*$NUM_PER_PAGE)-$NUM_PER_PAGE).','.$NUM_PER_PAGE, $yap);
	$a = 'normal';
	while($data = mysql_fetch_assoc($query_all_members)) {
		echo "
			<tr class='$a'>
				<td>{$data['name']}</td><td>{$data['location']}</td><td>{$data['shipType']}</td>
			</tr>
		";
		if ($a!="normal") $a="normal"; else $a="qrg";
	}
	echo "</table>";
	$bpage = (($page-1)<1)?1:$page-1;
	$npage = (($page+1)>$total_pages)?$total_pages:$page+1;
	echo "<span> <a href=?p=mbrtrk&page={$bpage}> Prev</a> Page {$page} of {$total_pages} <a href=?p=mbrtrk&page={$npage}>Next</a></span><br />Managed By Yapeal API.";
?>
